﻿toggle = function (fsid)
{
    var div = $id("div_" + fsid);
    var btn = $id("btn_" + fsid);
    var load = $id("load_" + fsid);
        
    var display = "";
    
    if( div.style.display != "none" )
    {
        display = "none";
    }
    
    div.style.display = display;
    btn.style.display = display;
    load.style.display = display;
}

CV_Update = function()
{
    var load = $id("load_CVReal");
    var btn = $id("btn_CVReal");
    if(confirm("save changes?"))
    {
        // di sini kirim data perubahannya
        var input = getData();
        if(input)
        {
            btn.style.display = "none";
            load.innerHTML = "<img src='" + LOADING.src + "' alt='' />"; 
            //alert(input);
            cbkReal_c.PerformCallback(input); 
        }
        else
        {
            btn.style.display = "block";
            load.innerHTML = "";
        }
    }
}
getData = function()
{
    var inputs = $nm("txt");
    var output = "";
    var iEmptyValueCount = 0;
    var iNotUploadedCount = 0;
    
    for( var i=0; i < inputs.length; i++ )
    {
        if( i > 0 )
        {
            output += DELIMITER;
        }
        
        var item = inputs[i];
        var lov = $id("lov_" + item.id);
        
        if( lov == null )
        {
            output += item.id + NEWLINE + item.value;
            if(item.value == "")
            {
                iEmptyValueCount++;
                item.style.backgroundColor = "#FFFFFF";
            }
            var uplbtn = $id("uplbtn_" + item.id);
            
            if( uplbtn != null && item.value != "" )
            {
                item.style.backgroundColor = "#FFAAAA";
                iNotUploadedCount++;
            }
        }
        else
        {
            var lovh = $id("lovh_" + item.id);
            output += lov.value + NEWLINE + lovh.value + NEWLINE + item.value;
                   
        }
    }
    var sxError = "";
    
    
    if( iEmptyValueCount > 0 )
    {
        sxError += "terdapat field isian yang belum diisi! ";
    }
    if (iNotUploadedCount > 0)
    {
        sxError += "terdapat file yang belum di upload";
    }
    if( sxError != "" )
    {
        alert(sxError);
        return false;
    }
    
    return output;
}
cbkReal_c_CallbackComplete = function(e){
    window.location = "CVView.aspx?cvid="+ e.result;    
}
ShowPopUp = function(iCPID, isNewCP)
{
    var div = $id("popuplayer");
    div.style.display = "block";
    div.innerHTML = "<img src='" + LOADING.src + "' alt='' />";
    renderFirst();
    
    cbkView_c.PerformCallback("SHOW" + DELIMITER + iCPID + DELIMITER + isNewCP);
}
closeCPInfo = function()
{
    var div = $id("popuplayer");
    div.innerHTML = "";
    div.style.display = "none";
}
cbkView_c_CallbackComplete = function(e){
    if( e.parameter.startsWith("SHOW") )
    {
        var div = $id("popuplayer");
        div.innerHTML = e.result;
    }
    else
    {
        closeCPInfo();
    }
}